<?php

class testController extends baseController
{
	
	function getSystem(){
	$sys = $_SERVER['HTTP_USER_AGENT'];
	if(stripos($sys, "NT 6.1"))
	   $os = "Windows 7";
	elseif(stripos($sys, "NT 6.0"))
	   $os = "Windows Vista";
	elseif(stripos($sys, "NT 5.1"))
	   $os = "Windows XP";
	elseif(stripos($sys, "NT 5.2"))
	   $os = "Windows Server 2003";
	elseif(stripos($sys, "NT 5"))
	   $os = "Windows 2000";
	elseif(stripos($sys, "NT 4.9"))
	   $os = "Windows ME";
	elseif(stripos($sys, "NT 4"))
	   $os = "Windows NT 4.0";
	elseif(stripos($sys, "98"))
	   $os = "Windows 98";
	elseif(stripos($sys, "95"))
	   $os = "Windows 95";
	elseif(stripos($sys, "Mac"))
	   $os = "Mac";
	elseif(stripos($sys, "Linux"))
	   $os = "Linux";
	elseif(stripos($sys, "Unix"))
	   $os = "Unix";
	elseif(stripos($sys, "FreeBSD"))
	   $os = "FreeBSD";
	elseif(stripos($sys, "SunOS"))
	   $os = "SunOS";
	elseif(stripos($sys, "BeOS"))
	   $os = "BeOS";
	elseif(stripos($sys, "OS/2"))
	   $os = "OS/2";
	elseif(stripos($sys, "PC"))
	   $os = "Macintosh";
	elseif(stripos($sys, "AIX"))
	   $os = "AIX";
	else
	   $os = "未知操作系统";

	return $os;
	}

	function getBrowser(){
	$sys = $_SERVER['HTTP_USER_AGENT'];
	if(stripos($sys, "NetCaptor") > 0)
	   $exp = "NetCaptor";
	elseif(stripos($sys, "Firefox/") > 0){
	   preg_match("/Firefox\/([^;)]+)+/i", $sys, $b);
	   $exp = "Mozilla Firefox ".$b[1];
	}elseif(stripos($sys, "MAXTHON") > 0){
	   preg_match("/MAXTHON\s+([^;)]+)+/i", $sys, $b);
	   preg_match("/MSIE\s+([^;)]+)+/i", $sys, $ie);
	   $exp = $b[0]." (IE".$ie[1].")";
	}elseif(stripos($sys, "MSIE") > 0){
	   preg_match("/MSIE\s+([^;)]+)+/i", $sys, $ie);
	   $exp = "Internet Explorer ".$ie[1];
	}elseif(stripos($sys, "Netscape") > 0)
	   $exp = "Netscape";
	elseif(stripos($sys, "Opera") > 0)
	   $exp = "Opera";
	else
	   $exp = "未知浏览器";

	return $exp;
	}
	
	function getIP()
	{
		static $realip;
		if (isset($_SERVER)){
			if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])){
				$realip = $_SERVER["HTTP_X_FORWARDED_FOR"];
			} else if (isset($_SERVER["HTTP_CLIENT_IP"])) {
				$realip = $_SERVER["HTTP_CLIENT_IP"];
			} else {
				$realip = $_SERVER["REMOTE_ADDR"];
			}
		} else {
			if (getenv("HTTP_X_FORWARDED_FOR")){
				$realip = getenv("HTTP_X_FORWARDED_FOR");
			} else if (getenv("HTTP_CLIENT_IP")) {
				$realip = getenv("HTTP_CLIENT_IP");
			} else {
				$realip = getenv("REMOTE_ADDR");
			}
		}
		return $realip;
	}
	
	public function show()
	{
		//Debug::dump(AclHelper::check_uan(2, 'read', 6));
		//echo microtime(true)-$GLOBALS['BTIME'];

		/*
		Debug::pre(
				//UserHelper::add('stork', '123', '小马虎', '1')
				//UserHelper::joinGroup('1', '2')	//($user_id, $group_id)
				User::getList(1)
				);
				*/
//		echo Sno::cgen('indent');
		
		//测试程序开始
		echo UserTrack::get();
		Debug::pre($_SERVER);
	}

	public function tpl(){
		$this->assign('now', array(time()));
		$this->display();
	}

	public function filter(){
		//$cont = file_get_contents('http://www.taobao.com/index_global.php');
		$cont = <<<HTML
<script>alert('Ook');</script>
<style>div{border:1px solid red;}</style>
<div>hello,world</div>
HTML;

		$now = microtime(true);
		$s = FilterHelper::sanitize($cont);

		echo "Duration: ", (microtime(true)-$now)*1000, " ms </br>\n";
		echo $s;

	}

	public function proof(){
		//header('Content-type: text/html; charset=gbk');
		if(fetch_a_char('proof')){
			echo ProofHelper::compare(fetch_a_char('proof'))
				? 'Yes' : 'No' ;
		}

		$url = url('test-proof2');
		echo <<<HTML
<img src='$url' />
<form method="post">
<input type="text" name="proof" />
<input type="submit" />
</form>
HTML;
	}

	public function proof2(){
		ProofHelper::draw();
	}
	public function proof3(){
		ImageHelper::proof('q9Q oO0');
	}

	public function priv(){
		$list = PrivTableHelper::getTree( 36, 1 );

		$ids  = self::priv2($list);
		Debug::pre($ids);

#		Db::get('PrivTable')->update(array('deleted'=>1))->where(array('id', 'in', $ids))->exec();
	}
	public function priv2($list){
		$ids = array();
		foreach($list as $n){
			$ids[] = $n['id'];
			if(!empty($n['nodes'])){
				$ids = array_merge($ids, self::priv2($n['nodes']));
			}
		}
		return $ids;
	}

	public function regx(){
		$html = <<<HTML
		<img src="xxxxxx.jpg" style="border:1px solid red;" /> <h5>hi</h5> 
		<script>
alert("OK");
		</script>
			<span> okokok</span>
HTML
		;
		echo FilterHelper::sanitize($html);
		/*
		if(1){
			//反向预搜索
			$str = '<img src="xxx\"xxx" id="okok" />';
			$str = str_replace('\\', '_^%_', $str); //使用"\"有问题，换成特殊字符
			$reg = '~
					([\'"])
						(.*?)
						(?<!_\^%_)
					\1
					~sx';
		}
		else{
			//递归
			$str = '$b["b_name"].nodes[$c.cid][$f.xx.00]'; #[$c[$d["d_name"]]]
			$reg = '~
					(\$\w+)?
					(
						\[
							(?:
								"\w+"
								|
								(?R)
							)
						\]
						|
						(\.\w+)
					)+?
					~x';
		}

		preg_match_all($reg, $str, $m);
		Debug::pre($m);
		*/

		/*
		$exp = '';
		foreach($m[2] as $k=>$v){
			if($m[1]){
				$exp .= "{$m[1][$k]}";
			}
			if($m[2][$k]){
				if('.'==substr($v,0,1)){
					$exp .= '["'.substr($v,1).'"]';
				}
				else{
					$exp .= $v;
				}
			}
		}

		echo $exp;
		*/
	}

	public function where(){
		//SELECT * FROM `procure_demand` WHERE (summary_id is null or summary_id =0)

		$list = Db::get('Demand')->select()->where(array('summary_id', 'is', 'null'), 'OR', array('summary_id'=>0))->getAll();
		Debug::pre(Db::get('Demand')->lastSql());
		$list = Db::get('Demand')->select()->where(array('summary_id', 'is', 'null'), array('summary_id'=>0))->getAll();
		Debug::pre(Db::get('Demand')->lastSql());
		
	}

	public function reviewer(){
		$list = ReviewerHelper::getList(1, 19);
		foreach($list as &$l){
			$l['status'] = ReviewerHelper::flow2txt($l['pass']);
		}
		Debug::pre(
				$list
				);

		#Debug::pre(ReviewerHelper::getCursor(1, 19));

		Debug::pre(ReviewerHelper::audit(1, 19, 2, 1, '备注部分'));

		Debug::dump(ReviewerHelper::haspass(1, 19));
		echo ReviewerHelper::getLastError();
		
	}

	public function rev_er(){
		Debug::pre(ReviewerHelper::getDemandByUser(1));
		ReviewerHelper::getIndentByUser(1);
		
		echo Db::get('Indent')->lastSql();

	}
}


?>
